<?php

class Zones_model extends CI_Model{
	
	public function __construct(){
		parent::__construct();
	}
	
	function create(){
		$data = array(
					'country_id' => $this->input->post('country_id'),
					'name' =>  $this->input->post('name'),
					'code' => $this->input->post('code'),
					'status' => $this->input->post('status')
				);
		$this->db_front->insert('zone', $data);	
	}
	
	function getAll($page='', $limit=''){
		if(!empty($limit))
		$this->db_front->limit($limit,$page);
		$query = $this->db_front->get('zone');
		if($query -> num_rows() > 0){
			foreach ($query -> result() as $rows){
				$data[] = $rows;	
			}	
			return $data;
		}	
	}
	
	function update($zone_id){
		$data = array(
					'country_id' => $this->input->post('country_id'),
					'name' =>  $this->input->post('name'),
					'code' => $this->input->post('code'),
					'status' => $this->input->post('status')
				);
        $this->db_front->where('zone_id', $zone_id);
        $this->db_front->update('zone', $data);
	}
	
	function select($zone_id){
        return $this->db_front->get_where('zone', array('zone_id'=>$zone_id))->row();
    }
	
	function delete($zone_id){
		$this->db_front->delete('zone', array('zone_id'=>$zone_id));
	}
	
	function get_countries(){
		$query = $this->db_front->get('country');
		if($query -> num_rows() > 0){
			foreach ($query -> result() as $rows){
				$data[] = $rows;	
			}	
			return $data;
		}	
	}
	
}

?>